package cn.psvmc.cxzapi.controller.order;

import cn.psvmc.cxzapi.model.common.SearchEntity;
import cn.psvmc.cxzapi.model.order.TOverdueType;
import cn.psvmc.cxzapi.response.*;
import cn.psvmc.cxzapi.service.order.TOverdueTypeService;
import cn.psvmc.cxzapi.util.PageUtil;
import cn.psvmc.cxzapi.util.ToolUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 逾期类型表相关操作
 *
 * @Author auto
 * @Date 2025-01-19
 */
@RestController
@RequestMapping("/overdueType")
public class TOverdueTypeController {

    @Resource
    private TOverdueTypeService tOverdueTypeService;

    /**
     * @Author auto 2025-01-19 新增逾期类型表
     * @Param tOverdueType 逾期类型表
     * @Return cn.psvmc.cxzapi.response.Result
     */
    @PostMapping("/add")
    public Result add(@RequestBody TOverdueType tOverdueType) {
        int addResult = tOverdueTypeService.add(tOverdueType);
        if (addResult > 0) {
            return ResultGenerator.genSuccessResult("保存成功！");
        }
        return ResultGenerator.genFailResult("保存失败！");
    }

    /**
     * @Author auto 2025-01-19 更新逾期类型表
     * @Param tOverdueType 逾期类型表模型
     * @Return cn.psvmc.cxzapi.response.Result
     */
    @PostMapping("/edit")
    public Result edit(@RequestBody TOverdueType tOverdueType) {
        ToolUtils.validation(new Object[]{tOverdueType.getOtid(), "id", 1});
        int updateResult = tOverdueTypeService.edit(tOverdueType);
        if (updateResult > 0) {
            return ResultGenerator.genSuccessResult("更新成功！");
        }
        return ResultGenerator.genFailResult("更新失败！");
    }

    /**
     * @Author auto 2025-01-19 删除逾期类型表
     * @Param tOverdueType
     * @Return cn.psvmc.cxzapi.response.Result
     */
    @PostMapping("/delete")
    public Result delete(@RequestBody TOverdueType tOverdueType) {
        Integer id = tOverdueType.getOtid();
        ToolUtils.validation(new Object[]{id, "id", 1});
        tOverdueTypeService.delete(id);
        return ResultGenerator.genSuccessResult("删除成功！");
    }

    /**
     * @Description 管理列表
     * @Date 2025/1/19 22:48
     * @Author YWX
     * @Param [entity]
     * @Return cn.psvmc.cxzapi.response.PageResult2
     **/
    @PostMapping("/list")
    public PageResult2 list(@RequestBody SearchEntity entity) {
        Page<TOverdueType> queryPage = new Page<>(entity.getPage(), entity.getSize());
        return PageUtil.getPageResult2(tOverdueTypeService.list(queryPage, entity));
    }

    /**
     * @Description 选择列表
     * @Date 2025/1/19 22:52
     * @Author YWX
     * @Param []
     * @Return cn.psvmc.cxzapi.response.Result
     **/
    @PostMapping("/list_sel")
    public Result listForSel() {
        return ResultGenerator.genSuccessResult("查询成功！", tOverdueTypeService.listForSel());
    }
}
